<template>
  <div class="login">
    <div class="loginBox">
      <div class="imgs fl"></div>
      <el-form ref="form" :model="form" :rules="rules" class="fl">
        <el-form-item prop="email" label="" class="email">
          <el-input
            prefix-icon="el-icon-message"
            placeholder="请输入登录邮箱号"
            v-model="form.email"
            @blur="isEmailSuccess"
            minlength="16"
            maxlength="50">
          </el-input>
        </el-form-item>
        <el-form-item prop="smsCode">
          <el-input
            v-model.number="form.validate"
            placeholder="请输入邮箱随机验证码"
            auto-complete="off"
            prefix-icon="el-icon-tickets"
            class="validate" maxlength="10"></el-input>
          <el-button type="primary" @click="onValidate" :disabled="isDisabled" class="button">{{msg}}</el-button>
        </el-form-item>
        <el-form-item class="sign">
          <el-button type="primary" @click="signIndex">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {getSessionStorage, objKeySort} from 'common/js/utils'
  import {decrypted, aesEncrypt, md5} from 'common/js/encrypt'
  import {errorCallback} from 'common/js/ajaxCallback'

  export default {
    data () {
      return {
        form: {
          email: '',
          smscode: ''
        },
        rules: {
          email: [
            {required: true, message: '请输入邮箱地址', trigger: 'blur'},
            {type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}
          ],
          smsCode: [
            {required: true, message: '验证码不能为空', trigger: 'blur'}
          ]
        },
        isDisabled: false,
        msg: '发送验证'
      }
    },
    methods: {
      // 发送验证码
      onValidate () {
        this._times(120)
      },
      // 设置几秒后可以重新点击
      _times (num) {
        this.isDisabled = true
        const self = this
        setTimeout(function () {
          if (num >= 0) {
            self.msg = '倒计时' + num + 's'
            num--
            self._times(num)
          } else {
            self.isDisabled = !self.isDisabled
            self.msg = '重新发送'
          }
        }, 1000)
      },
      // 判断是否是系统邮箱
      isEmailSuccess () {
      },
      // 登录跳转
      signIndex () {
        let self = this
        let obj = {
          name: 1,
          age: 1,
          secret: getSessionStorage('secret'),
          telephone: '15110659841'
        }
        // let newValue = encrypted.encrypt(JSON.stringify(objKeySort(obj)))
        let aes = aesEncrypt(obj, '268ec48359d9cd64')
        // console.log(aesDecrypt(aes, '268ec48359d9cd64'))
        let newValue = aes + md5(JSON.stringify(objKeySort(obj)), '268ec48359d9cd64')
        // console.log(aes)
        // console.log(newValue)
        // console.log(decrypted.decrypt(newValue))
        // console.log(JSON.stringify(objKeySort(obj)))
        let postData = {
          data: newValue,
          ty: 1,
          tn: '445eed737fc7939c112c9d7a4f9bc643'
        }
        this.axios.post('/api/testCitys/list.do', this.$Qs.stringify(postData))
          .then(response => {
            let data = response.data
            console.log(data)
            let list = decrypted.decrypt(data.data)
            console.log(list)
            self.$router.replace('login')
          })
          .catch(errorCallback)
      }
    }
  }
</script>

<style lang="less" ref="stylesheet/less" scoped>
  .login {
    width: 100%;
    height: 100%;
    background: url('./loginBg.jpg') no-repeat center;
    background-size: cover;
    display: flex;
    align-items: center;
    .loginBox {
      width: 940px;
      height: 500px;
      background-color: #fff;
      margin: 0 auto;
      .imgs {
        width: 400px;
        height: 100%;
        background: url('./xinyongpay.jpg') no-repeat center;
        background-size: cover;
      }
      .el-form {
        width: 540px;
        padding-top: 141px;
        .el-form-item {
          margin: 0 auto 35px;
          width: 374px;
          font-size: 0;
          /deep/ .el-form-item__content {
            font-size: 0;
            input {
              border: none;
              border-bottom: 1px solid #d8d8d8;
              border-radius: 0;
            }
            .validate {
              width: 274px;
            }
            .el-button {
              border-radius: 0;
              &.button {
                width: 100px;
                height: 40px;
                padding: 0;
              }
            }
          }
          &.sign {
            padding-top: 40px;
            text-align: left;
            .el-button {
              width: 130px;
              height: 40px;
            }
          }
        }
      }
      .el-button--primary.is-disabled,
      .el-button--primary.is-disabled:active,
      .el-button--primary.is-disabled:focus,
      .el-button--primary.is-disabled:hover {
        background-color: #b8b8b8;
        border-color: #b8b8b8;
      }
    }
  }
</style>
